#/bin/bash
# Fills directories with proper files


for temp in 320 390 520
do
    #Make directories
#	mkdir ./$temp"K"

	for pressure in 5 10 20 50
    do

        #Make directories
#        mkdir ./$temp"K"/$pressure"MPa"
       
        for phase in EQ PROD
        do

            #Make directories
#            mkdir ./$temp"K"/$pressure"MPa"/$phase
                  
            #Add executable to all folders
            cp co2model "./$temp"K"/$pressure"MPa"/$phase/"

            #Generate and place configuration files
            cp rev_micelle_mc.inp rev_micelle_mc_working.inp

           vim -c "%s/%TEMP%/$temp/g|%s/%PRESSURE%/$pressure"000000"/g|%s/%PHASE%/$phase/g|wq" rev_micelle_mc_working.inp

            #Create PBS file 
            cp cgmodel_gpu.pbs cgmodel_gpu_working.pbs
            vim -c "%s/%TEMP%/$temp"K"/g|%s/%PRESSURE%/$pressure"MPa"/g|%s/%PHASE%/$phase/g|wq" cgmodel_gpu_working.pbs

            if [ "$phase" == "EQ" ]
            then
               vim -c "%s/%NPT%/ON/g|%s/%MCSTEPS%/1000000/g|wq" rev_micelle_mc_working.inp
              vim -c "%s/%COPYCONFIG%/cp eqconf.out ..\/PROD\/eqconf.out/g|wq" cgmodel_gpu_working.pbs
            fi

            if [ "$phase" == "PROD" ]
            then
               vim -c "%s/%NPT%/ON/g|%s/%MCSTEPS%/5000000/g|wq" rev_micelle_mc_working.inp
               vim -c "%s/%COPYCONFIG%/ /g|wq" cgmodel_gpu_working.pbs
            fi

            mv rev_micelle_mc_working.inp "./$temp"K"/$pressure"MPa"/$phase/rev_micelle_mc.inp"
            mv cgmodel_gpu_working.pbs "./$temp"K"/$pressure"MPa"/$phase/cgmodel_gpu.pbs"

        done
        
        #Add starting configuration (assuming all the same)
        cp active_configuration.xyz "./$temp"K"/$pressure"MPa"/EQ/"
    done
done

